package num1572;

/**
 * @author : DuJiabao
 * @Project : sword-finger-offer
 * @Time : 2021/4/10 9:44
 * @Desc :
 */
class Solution {
  public int diagonalSum(int[][] mat) {
    if (mat == null || mat.length < 1 || mat[0].length < 1) return 0;
    int length = mat.length;
    int res = 0;
    for (int i = 0; i < length; i++) {
      res += mat[i][i];
      res += mat[i][length - i - 1];
    }
    if (length % 2 == 1) {
      int center = length / 2;
      res -= mat[center][center];
    }
    return res;
  }

  public static void main(String[] args) {
    int[][] mat = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    int res = new Solution().diagonalSum(mat);
    System.out.println(res);
  }
}
